package com.eqdd.yiqidian.ui.mine;

import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;

import com.eqdd.annotation.datasave.ToSave;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.choose.HangyeBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditChooseBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditTimeBean;
import com.eqdd.yiqidian.bean.utils.MultiChooseBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.utils.MultiChooseTestUtil;
import com.eqdd.yiqidian.utils.SingleChooseUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.ActionSheetDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

import chihane.jdaddressselector.BottomDialog;
import chihane.jdaddressselector.ISelectAble;

/**
 * Created by 吕志豪 on 17-10-12  上午10:21.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class AddProjectExpActivity extends SlimBaseMultiEditActivity {


    private RecyclerViewCustom dataBinding;

    private String msg;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "添加项目经验");
        initTopRightText("提交", v -> {
            if (checkParam()) {
                OkGo.<HttpResult>post(HttpConfig.BASE_URL + HttpConfig.ADD_PROJECT_EXP)
                        .params("userGuid", user.getGuid())
                        .params("ownedCompany", setParam(1))
                        .params("projectName", setParam(0))
                        .params("startTime", setParam(2))
                        .params("endTime", setParam(3))
                        .params("duty", setParam(5))
                        .params("projectDescription", setParam(6))
                        .params("projectURL", setParam(4))
                        .params("isOvert", setParam(7).equals("不公开")?0:1)
                        .execute(new DialogCallBack<HttpResult>(AddProjectExpActivity.this) {
                            @Override
                            public void onSuccess(Response<HttpResult> response) {
                                HttpResult httpResult = response.body();
                                ToastUtil.showShort(httpResult.getMsg());
                                if (httpResult.getStatus() == 200) {
                                    setResult(Config.SUCCESS);
                                    finish();
                                }
                            }
                        });
            } else {
                ToastUtil.showShort(msg);
            }
        });
    }

    private boolean checkParam() {
        for (int i = 0; i < 8; i++) {
            if (TextUtils.isEmpty(setParam(i))) {
                msg = "请补全所有信息";
                return false;
            }
        }
        return true;
    }

    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {

    }

    @Override
    protected void setEditBeans() {

        datas.add(new SlimEditEnterBean("项目名称", "", 0, "请填写"));
        datas.add(new SlimEditEnterBean("所在企业", "", 1,  "请填写"));
        datas.add(new SlimEditTimeBean("项目开始时间", "", 2, "请选择").setType(Config.YEAR_MONTH_DAY_TYPE));
        datas.add(new SlimEditTimeBean("项目结束时间", "", 3, "请选择").setType(Config.YEAR_MONTH_DAY_TYPE));
        datas.add(new SlimEditEnterBean("项目URL地址", "", 4, "请填写"));
        datas.add(new SlimEditEnterBean("项目职责", "", 5,  "请填写"));
        datas.add(new SlimEditEnterBean("项目描述", "", 6, "请填写"));
        datas.add(new SlimEditChooseBean("是否公开", "", 7, "请选择", new String[]{"不公开", "公开"}));

    }
}
